{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "78922966-f039-4bde-baed-893afbc6492a",
   "metadata": {},
   "outputs": [],
   "source": [
    "from mythic import mythic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6fdb246e-7fd0-4660-9ad0-01431ea1e435",
   "metadata": {},
   "outputs": [],
   "source": [
    "mythic_instance = await mythic.login(\n",
    "        username=\"mythic_admin\",\n",
    "        password=\"mythic_password\",\n",
    "        server_ip=\"mythic_nginx\",\n",
    "        server_port=7443,\n",
    "        timeout=-1\n",
    "    )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bb78634e-0127-48bf-b366-d033768841c3",
   "metadata": {},
   "outputs": [],
   "source": [
    "## Send a JSON agent message as though it came from a certain callback and parse the response ###\n",
    "# This currently only works with 36 character UUID Strings and no translation containers\n",
    "# Must specify a C2 Profile and the Agent Callback ID so Mythic can look up the right crypto\n",
    "resp = await mythic.send_callback_agent_message_dict(mythic=mythic_instance,\n",
    "                                                     c2_profile=\"http\",\n",
    "                                                     agent_callback_id=\"69ed4277-4832-4d94-8536-d4137b97d7a0\",\n",
    "                                                     message={\n",
    "                                                         \"action\": \"update_info\",\n",
    "                                                         \"user\": \"bob\"\n",
    "                                                     })\n",
    "print(resp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fef01140-4201-406e-bc69-e1b756035705",
   "metadata": {},
   "outputs": [],
   "source": [
    "## Take a JSON message that a callback would send, encrypt it, and optionally include the UUID + base64 encode ##\n",
    "encryptedMsg = await mythic.local_encrypt_agent_message(mythic=mythic_instance,\n",
    "                                                        agent_callback_id=\"69ed4277-4832-4d94-8536-d4137b97d7a0\",\n",
    "                                                        include_uuid=True,\n",
    "                                                        base64_result=True,\n",
    "                                                        message={\n",
    "                                                            \"action\": \"update_info\",\n",
    "                                                            \"user\": \"heracles\"\n",
    "                                                        }\n",
    "                                                        )\n",
    "print(encryptedMsg)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a3dc3c6f-296b-4bd8-9839-bab1acf7e8e3",
   "metadata": {},
   "outputs": [],
   "source": [
    "## Take an existing, base64 message that an agent would send and forward it to Mythic, optionally processing the response ##\n",
    "resp = await mythic.send_callback_agent_message_base64(mythic=mythic_instance,\n",
    "                                                       c2_profile=\"http\",\n",
    "                                                       message=encryptedMsg,\n",
    "                                                       agent_callback_id=\"69ed4277-4832-4d94-8536-d4137b97d7a0\",\n",
    "                                                       decrypt_response=True)\n",
    "print(resp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b31bcf1c-7cc4-48ee-a539-b9a86373dcaa",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
